//
//  MeInterestScr.m
//  ZITHER
//
//  Created by weixin on 2018/10/16.
//  Copyright © 2018年 weixn. All rights reserved.
//

#import "MeInterestScr.h"
#import "MyInterestVC.h"

@implementation MeInterestScr

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self defaultConfiguration];
        [self setUI];
    }
    return self;
}

-(void)defaultConfiguration{
    self.bounces = NO;
    self.showsHorizontalScrollIndicator = NO;
    self.bounces = NO; // 默认为YES 取消设置NO
    // 当bounces属性为NO时，以下两个属性设置无效
    self.alwaysBounceHorizontal = YES; // 水平方向弹簧效果
    self.alwaysBounceVertical = YES; // 垂直方向弹簧效果
    self.decelerationRate = 0.1; // 值域 0~1 值越小减速停止的时间越短
    self.backgroundColor = [UIColor whiteColor];
    self.pagingEnabled = YES;
    self.contentSize = CGSizeMake(kScreenW*2,0);
    self.delegate = self;
}


-(void)setUI{

    [self addSubview:self.tbvMyInterest];
    [self addSubview:self.tbvInterestMy];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    if (scrollView.contentOffset.x == 0) {
        [self changePage:0];
    }else if (scrollView.contentOffset.x == SCREEN_WIDTH){
        [self changePage:1];
    }
}

-(void)changePage:(int)index{
    MyInterestVC *vc  = (MyInterestVC*)[self getViewController:[MyInterestVC class]];
    [UIView animateWithDuration:0.2 animations:^{
        CGFloat width = [NSString textWidth:@"我关注的" font:14 height:15];
        CGRect rect = self.frame;//付值
        if (index ==0) {
            rect = CGRectMake(vc.baseNavigationView.NavViewStyleMyInterest.leftTitleBtn.frame.origin.x+10, NaviHeight-2,width,2);
        }else{
            rect = CGRectMake(vc.baseNavigationView.NavViewStyleMyInterest.rightTitleBtn.frame.origin.x+10, NaviHeight-2,width,2);
        }
        vc.baseNavigationView.NavViewStyleMyInterest.viewBlcak.frame = rect;

    }];
}

- (MeInterestTbv *)tbvMyInterest{
if (!_tbvMyInterest) {
    _tbvMyInterest = [[MeInterestTbv alloc]initializeFrame:CGRectMake(0, 0, kScreenW,self.frame.size.height) isMj:1 isEstimatedRowHeight:YES addRegisterNib:@[@"MeInterestCell"]];
    _tbvMyInterest.type = 0;
    }
    return _tbvMyInterest;
}

- (MeInterestTbv *)tbvInterestMy{
    if (!_tbvInterestMy) {
        _tbvInterestMy = [[MeInterestTbv alloc]initializeFrame:CGRectMake(kScreenW, 0, kScreenW, self.frame.size.height) isMj:1 isEstimatedRowHeight:YES addRegisterNib:@[@"MeInterestCell"]];

        _tbvInterestMy.type = 1;
    }
    return _tbvInterestMy;
}
@end
